<?php

		include_once '../controladores/ControladorAplicaciones.php';
		include_once '../controladores/ControladorUsuarios.php';		
		include_once "../config.inc.php";
		
		$newappName = $_POST["app_name"];
		$appDescription = $_POST["app_description"];
		$appVersion = $_POST["app_version"];
		
		if (!empty($_GET['usr']) && !empty($_GET['app']) && !empty($_GET['sec'])){
			$usr = $_GET['usr'];
			$app = $_GET['app'];
			$secc = $_GET['sec'];
			
		}

	// Buscando el nombre de la carpeta a cambiar.
	
		$command = new ControladorAplicaciones();	
		$appName = $command->searchApplicationName($app);
	
		$command = new ControladorUsuarios();
		$userEmail = $command->obtainUserEmail($usr);

		$targetApplication = ROUTE_APPLICATIONS_USERS.$userEmail."/Applications/".$appName;		
	
	//------------------------------------------------------
	
		$command = new ControladorAplicaciones();

		$updatedData = array("app_id" => $app, "app_name" => $newappName, "app_description" => $appDescription, "app_version" => $appVersion);
		
		$command->updateApplication($updatedData);

 	// Ahora se buscará el nombre de la aplicación nueva.
		
		$appName = $command->searchApplicationName($app);
		
		$newtargetApplication = ROUTE_APPLICATIONS_USERS.$userEmail."/Applications/".$appName;
		
		rename($targetApplication,$newtargetApplication);
				
	    header("Location:section_elements.php?usr=".$usr."&app=".$app."&sec=".$secc."");
?>